<?php



add_action('admin_menu', 'add_payment_paypal');
function add_payment_paypal()
{
   
add_menu_page('Payment Paypal', 'Payment Paypal','administrator','payment-paypal','form_config');

}

function form_config()
{
	
require_once TEMPLATEPATH .'/incs/payments/paypal/payment_db.php';
//require_once TEMPLATEPATH .'/incs/payments/paypal/payments.php';
require_once TEMPLATEPATH .'/incs/payments/paypal/paypal.php';	
?>
<div class="wrap">
 <div><h2>Config Payment Paypal</h2></div>
   <?php
        if(wp_verify_nonce($_POST['action_paypal_config'],'paypal_config'))
        {        	
        		
        	update_option('email_paypal',$_POST['email_paypal']);
        	update_option('current_money',$_POST['current_money']);
        	update_option('status_pp',$_POST['status_pp']);        	
        	echo '<h2>Saved Successful!</h2>';
        }
   
   ?>


<fieldset style="border:1px solid #ddd;">
<legend >Gobal Paypal</legend>
 <form action="" method="post">
      <table style="padding:10px;">
        <tr>
         <td>Trạng Thái:</td>
         <?php
         $status = get_option('status_pp') 
         ?>
         <td><select name="status_pp" style="width: 80px;">
		  <option <?php if($status=="Run") echo 'selected="selected"';?> value="Run">Chạy</option>
		  <option <?php if($status=="Test") echo 'selected="selected"';?> value="Test">Test</option>
            </select> 
            <?php echo $status;?>
            </td>
         </tr>
         <tr>
         <td>Paypal Email:</td>
         <td><input type="text" style="width:250px;" name="email_paypal" value="<?php echo get_option('email_paypal');?>"/></td>
         </tr>
         <tr>
         <td>Current Money:</td>
         <td>
         <?php $curent = get_option("current_money");?>
         <select name="current_money" style="width: 80px;">         
         	<option <?php if($curent=="USD") echo 'selected="selected"';?> value="USD">USD</option>
		  	<option <?php if($curent=="EURO") echo 'selected="selected"';?> value="EURO">EURO</option>
         </select>
         <?php echo $curent;?>
         </td>
         </tr>
		 <tr>
		 <td></td>
		 <td><input class="button-primary" type="submit" name="submit" value="Save"/></td>
		 </tr>
		
		</table>    
		 <?php wp_nonce_field('paypal_config','action_paypal_config')?>
		   </form>

</fieldset>


</div>
<?php
}

function money_type()
{
	 $arrs=array('USD','URO');
	 
 	 foreach ($arrs as  $ar)
 	 {
 	 	$html .='<option value="'.$ar.'">'.$ar.'</option>';
 	 }

   return $html;
	
}




function form_html_checkout()
{
$paypal_email=NULL;
  if(get_option('email_paypal'))
  {
     $paypal_email=get_option('email_paypal');
  
  }
  else 
  {
      $paypal_email=get_option('admin_email');
  }
     $url_return=get_bloginfo('url').'/paypal-return';
     $url_cancle=get_bloginfo().'/paypal-cancle';  
  ?>
  
  
  
  
  
  
  <?php
  
}

function  form_html($customer_first_name,$customer_last_name,$customer_email,$item_name,$order_code,$price)
{
    ?>
    <form class="paypal" action="<?php echo get_bloginfo('url').'/paypal'?>" method="post" id="paypal_form">    
	<input type="hidden" name="cmd" value="_xclick" /> 
	<input type="hidden" name="item_name" value="<?php echo $item_name;?>" / >
    <input type="hidden" name="no_note" value="1" />
    <input type="hidden" name="currency_code" value="<?php echo get_option('current_money')?>" />
    <input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynow_LG.gif:NonHostedGuest" />
    <input type="hidden" name="first_name" value="<?php echo $customer_first_name;?>"  />
    <input type="hidden" name="last_name" value="<?php echo $customer_last_name?>"  />
    <input type="hidden" name="payer_email" value="<?php echo $customer_email;?>"  />
    <input type="hidden" name="item_number" value="<?php echo $order_code;?>" / >
    <input type="hidden" name="amount" value="<?php echo $price;?>" / >
    <input type="submit"  value="Submit Payment"/>
</form>
    
    
    <?php 


}






